class Solution {
    /**
     * 要注意的是p2 p3交换了位置
     */
    public ListNode swapPairs(ListNode head) {
        if(head==null || head.next==null)
            return head;
        ListNode root = new ListNode(-1, head);
        ListNode p1 = root, p3 = head.next;
        while (true){
            // swap p2,p3
            ListNode p2 = p1.next;
            p1.next = p3;
            p2.next = p3.next;
            p3.next = p2;

            if( p2.next==null || p2.next.next==null )
                break;
            p1 = p2;
            p3 = p2.next.next;
        }
        return root.next;
    }
}